﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration; // For SqlConnection
using System.Web.UI.WebControls;// Pass value as WebControls eg dropdownlist
using System.Net.Mail;
/// <summary>
/// Summary description for dbConn
/// </summary>
public class dbConn
{
	public dbConn()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    private static string ConnectionString
    {

        get
        {
            //return ConfigurationManager.ConnectionStrings["devTmsEPrd"].ConnectionString;
            //return ConfigurationManager.ConnectionStrings["prodTmsEPrd"].ConnectionString;
            return ConfigurationManager.ConnectionStrings["prod"].ConnectionString;
        }
    }
    public void populateState(DropDownList dd)
    {
        SqlDataReader reader;
        //SqlConnection conn = new SqlConnection(ConnectionString);
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["prod"].ConnectionString);
        // Both cmd are working
        //SqlCommand cmd = new SqlCommand(" SELECT DISTINCT address_master.state FROM address_master", conn); // working
        SqlCommand cmd = new SqlCommand("SELECT state_id, state_name FROM [dbo].[us_states] order by state_id ", conn);
        try
        {
            conn.Open();
            reader = cmd.ExecuteReader();
            dd.DataSource = reader;
            dd.DataValueField = "state_id";
            dd.DataTextField = "state_name";
            dd.DataBind();
            reader.Close();

        }
        finally
        {
            conn.Close();

        }

    }
    public void sendMail(string body, string from, string to, string subject)
    {
        string _body = body.ToString();
        // string delim = ";";
        SmtpClient MailObj = new SmtpClient("mail.avila.edu");
        MailMessage msg = new MailMessage();
        msg.From = new MailAddress(from.ToString());
        msg.To.Add(new MailAddress(to.ToString()));
        msg.Subject = subject.ToString();
        msg.Body = _body.ToString();
        msg.IsBodyHtml = true;
        MailObj.Send(msg);
    }
}
